<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('order');
$rep_id= abs(intval($_GET['rep_id']));
if($rep_id){
  $reorder = Table::Fetch('order',$rep_id);
  if($reorder['flag']&&$reorder['packageid']>0)
  {
  $idss=array();
  $package_old = Table::Fetch('package',$reorder['packageid']);
  $ids= Utility::ExtraDecode($package_old['team_id']);
           if($reorder['team_id']==9999999)
               {
			   $title=$package_old['title'].'<font color="#FF0000">购物车'.$reorder['id'].'</font>：';
			   $quantity=$package_old['quantity'];
               $cartinf = Utility::ExtraDecode($reorder['cartinf']); 
			         foreach($cartinf as $key=>$value)
                           {
                           array_unshift($ids,$key);
                           $teamuut = Table::Fetch('team', $key);
						   $title=$title.$teamuut['product']."[".$value."件]&nbsp;";
						   $quantity=$quantity+$value;
                           }
						  $package_n['title']=$title.'<br>'; 
						  $package_n['quantity']=$quantity;
						  $package_n['origin']=$package_old['origin']+$reorder['origin'];
			   }
			else
			{
  array_unshift($ids,$reorder['team_id']);
  $onesteam = Table::Fetch('team', $reorder['team_id']);
  $package_n['origin']=$package_old['origin']+$reorder['origin'];
  $package_n['quantity']=$package_old['quantity']+$reorder['quantity'];
  $package_n['title']=$package_old['title'].'<font color="#FF0000">订单号'.$onesteam['id'].'</font>：'.$onesteam['product']."[".$reorder['quantity']."件]&nbsp;";
             } 
  if($reorder['remark'])
  $package_n['remark']=$package_old['remark'].'订单号'.$reorder['id']."备注：".$reorder['remark']."<br>";;
  $idss=array_unique($ids);
  $idss= Utility::ExtraEncode($idss);
  $package_n['team_id']=$idss;
  Table::UpdateCache('order',$rep_id, array( 'flag' =>0));
 DB::Update('package',$reorder['packageid'],$package_n);
  }        
}
 redirect( WEB_ROOT . "/manage/goods/packageing.php");


